/*
 * Copyright (C) 拾光分享网 
 * All rights reserved, Designed By www.hiai.top.
 * Email：goodsking@163.com.
 */
package top.hiai._admin.comments;

import com.jfinal.plugin.activerecord.Page;
import top.hiai.common.model.Comments;

import java.util.Date;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top
* @Introduction 类的介绍
*/

public class CommentsAdminService {
	
	public static final CommentsAdminService me = new CommentsAdminService();
	
	private Comments commentsDao = new Comments().dao();

	/**
	 * 后台管理所有文章分页
	 */
	public Page<Comments> paginate(int pageNum,int pageSize) {
		Page<Comments> commentsPage = commentsDao.paginate(pageNum, pageSize, "select *", "from bbs_comments order by addtime desc");
		return commentsPage;
	}
	/**
	 * 根据ID查找
	 * @param tid
	 * @return
	 */
	public Comments findById(int tid) {
		return commentsDao.findById(tid);
	}
	
	/**
	 * 添加分类
	 * @param name
	 * @param sort
	 * @param remarks
	 * @return
	 */
	public Boolean commentsAdd(String name,int sort,String remarks){
		Comments comments = new Comments();
		comments.setName(name);
		comments.setSort(sort);
		comments.setRemarks(remarks);
		int random=(int)(Math.random()*6+1);
		comments.setImages(random+".png");
		comments.setAddtime(new Date());
		if(comments.save()){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 修改分类
	 * @param tid
	 * @param name
	 * @param sort
	 * @param remarks
	 * @return
	 */
	public Boolean commentsEdit(int tid,String name,int sort,String remarks){
		Comments comments = new Comments();
		comments.setTid(tid);
		comments.setName(name);
		comments.setSort(sort);
		comments.setRemarks(remarks);
		if(comments.update()){
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 删除分类
	 * @param tid
	 */
	public void commentsDelete(int tid){
		commentsDao.deleteById(tid);
	}

}